<%
'Cookie操作类,如果使用了加密应Use("Aes")
Class CookieClass
	'键值前缀,是否对Cookies值进行加密
	Private	s_mark, s_cooen

	'''构造
	Private Sub Class_Initialize()
		s_mark = ""
		s_cooen = False
	End Sub

	'''析构
	Private Sub Class_Terminate()
	End Sub

	'''设置Cookie键值前缀
	'p_s: String (字符串)
	Public Property Let Mark(Byval p_s)
		s_mark = p_s
	End Property

	'''获取Cookie键值前缀
	Public Property Get Mark()
		Mark = s_mark
	End Property

	'''设置是否对Cookies值进行加密
	'p_b: True/False (布尔值)
	Public Property Let Encode(ByVal p_b)
		s_cooen = p_b
	End Property

	'''获取是否对Cookies值进行加密
	Public Property Get Encode()
		IfEncode = s_cooen
	End Property

	'设置一个Cookie值
	'p_k: String (字符串)键值
	'p_v: Anything (任意值)Cookie值
	'p_o: Array/String (数组/字符串)可选属性：存活时长(分)/失效时间/Array(时间,路径,域)
	Public Sub [Set](Byval p_k, Byval p_v, Byval p_o)
		If s_cooen Then
			p_v = Aes.Encode(p_v)
		End If
        Response.Cookies(s_mark & p_k) = p_v
        If Not (IsNull(p_o) Or IsEmpty(p_o)) Then
            If IsArray(p_o) Then
                Dim t_l : t_l = UBound(p_o)
				If t_l > 0 Then
					If Trim(p_o(0)&"")<>"" Then
						If IsNumeric(p_o(0)) Then
							Response.Cookies(s_mark & p_k).Expires = Now()+Int(p_o(0))/60/24
						Else
							Response.Cookies(s_mark& p_k).Expires = p_o(0)
						End If
					End If
				End If
                If t_l > 1 Then
					If Trim(p_o(1)&"")<>"" Then
						Response.Cookies(s_mark & p_k).Path = p_o(1)
					End If
				End If
                If t_l = 2 Then
					If Trim(p_o(2)&"")<>"" Then
						Response.Cookies(s_mark & p_k).Domain = p_o(2)
					End If
				End If
            Else
                If p_o <> "" Then
					If IsNumeric(p_o) Then
						Response.Cookies(s_mark & p_k).Expires = Now()+Int(p_o)/60/24
					Else
						Response.Cookies(s_mark & p_k).Expires = p_o
					End If
				End If
            End If
        End If
    End Sub

	'''获取Cookie值
	'p_k: String (字符串)cookie键值
	Public Function [Get](Byval p_k)
		Dim t_v : t_v = Request.Cookies(s_mark & p_k)
		If s_cooen Then
			t_v = Aes.Decode(t_v)
		End If
        [Get] = t_v
    End Function
	
	'''取Cookie值(默认)
	'p_k: String (字符串)cookie键值
    Public Default Property Get Find(Byval p_k)
        Find = [Get](p_k)
    End Property

	'''删除某个Cookie值
	'p_k: String (字符串)cookie键值
	Public Sub Remove(Byval p_k)
		Response.Cookies(s_mark & p_k) = Empty
		Response.Cookies(s_mark & p_k).Expires = FormatDateTime(Now()-1)
    End Sub

	'''清空删除所有Cookie值
	Public Sub RemoveAll()
		Dim t_c,t_sk
		For Each t_c In Request.Cookies
			If Not(Request.Cookies(t_c).HasKeys) Then
				Response.Cookies(t_c) = Empty
			Else
				For Each t_sk In Request.Cookies(t_c)
					Response.Cookies(t_c)(t_sk) = Empty
				Next
			End if
			Response.Cookies(t_c).Expires = FormatDateTime(Now()-1)
		Next
	End Sub

	'''判断是否存在cookie
	'p_k: String (字符串)cookie键值
	Public Function Has(Byval p_k)
		Has = Not IsN([Get](p_k))
	End Function
	
	'''比较两个Cookie值是否相等(有问题,暂时不启用)
	'p_k1: String (字符串) Cookie 1 的键值
	'p_k2: String (字符串) Cookie 2 的键值
	Public Function [Compare](Byval p_k1, Byval p_k2)
		Dim t_c1 : t_c1 = [Get](p_k1)
		Dim t_c2 : t_c2 = [Get](p_k2)
		If TypeName(t_c1) <> TypeName(t_c2) Then
			[Compare] = False
		Else
			If TypeName(t_c1) = "Object" Then
				[Compare] = (t_c1 Is t_c2)
			Else
				If TypeName(t_c1) = "Variant()" Then
					[Compare] = (Join(t_c1, "^") = Join(t_c2, "^"))
				Else
					[Compare] = (t_c1 = t_c2)
				End If
			End If
		End If
	End Function
End Class
%>